home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-Native.exe / {app} / include / elements / CEGUIListboxItem.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-02  |  12.7 KB  |  447 lines

  1. /************************************************************************
  2.     filename:     CEGUIListboxItem.h
  3.     created:    8/6/2004
  4.     author:        Paul D Turner
  5.     
  6.     purpose:    Interface to base class for list items
  7. *************************************************************************/
  8. /*************************************************************************
  9.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  10.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  11.  
  12.     This library is free software; you can redistribute it and/or
  13.     modify it under the terms of the GNU Lesser General Public
  14.     License as published by the Free Software Foundation; either
  15.     version 2.1 of the License, or (at your option) any later version.
  16.  
  17.     This library is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.     Lesser General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU Lesser General Public
  23.     License along with this library; if not, write to the Free Software
  24.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25. *************************************************************************/
  26. #ifndef _CEGUIListboxItem_h_
  27. #define _CEGUIListboxItem_h_
  28.  
  29. #include "CEGUIBase.h"
  30. #include "CEGUIString.h"
  31. #include "CEGUIColourRect.h"
  32. #include "CEGUIRenderCache.h"
  33.  
  34. // Start of CEGUI namespace section
  35. namespace CEGUI
  36. {
  37. /*!
  38. \brief
  39.     Base class for list box items
  40. */
  41. class CEGUIEXPORT ListboxItem
  42. {
  43. public:
  44.     /*************************************************************************
  45.         Constants
  46.     *************************************************************************/
  47.     static const colour    DefaultSelectionColour;        //!< Default selection brush colour.
  48.  
  49.  
  50.     /*************************************************************************
  51.         Construction and Destruction
  52.     *************************************************************************/
  53.     /*!
  54.     \brief
  55.         base class constructor
  56.     */
  57.     ListboxItem(const String& text, uint item_id = 0, void* item_data = NULL, bool disabled = false, bool auto_delete = true);
  58.  
  59.  
  60.     /*!
  61.     \brief
  62.         base class destructor
  63.     */
  64.     virtual ~ListboxItem(void) {}
  65.  
  66.  
  67.     /*************************************************************************
  68.         Accessors
  69.     *************************************************************************/
  70.     /*!
  71.     \brief
  72.         return the text string set for this list box item.
  73.  
  74.         Note that even if the item does not render text, the text string can still be useful, since it
  75.         is used for sorting list box items.
  76.  
  77.     \return
  78.         String object containing the current text for the list box item.
  79.     */
  80.     const String&    getText(void) const        {return d_itemText;}
  81.     const String&    getTooltipText(void) const        {return d_tooltipText;}
  82.  
  83.     /*!
  84.     \brief
  85.         Return the current ID assigned to this list box item.
  86.  
  87.         Note that the system does not make use of this value, client code can assign any meaning it
  88.         wishes to the ID.
  89.  
  90.     \return
  91.         ID code currently assigned to this list box item
  92.     */
  93.     uint    getID(void) const            {return d_itemID;}
  94.  
  95.  
  96.     /*!
  97.     \brief
  98.         Return the pointer to any client assigned user data attached to this lis box item.
  99.  
  100.         Note that the system does not make use of this data, client code can assign any meaning it
  101.         wishes to the attached data.
  102.  
  103.     \return
  104.         Pointer to the currently assigned user data.
  105.     */
  106.     void*    getUserData(void) const        {return d_itemData;}
  107.  
  108.  
  109.     /*!
  110.     \brief
  111.         return whether this item is selected.
  112.  
  113.     \return
  114.         true if the item is selected, false if the item is not selected.
  115.     */
  116.     bool    isSelected(void) const        {return d_selected;}
  117.  
  118.  
  119.     /*!
  120.     \brief
  121.         return whether this item is disabled.
  122.  
  123.     \return
  124.         true if the item is disabled, false if the item is enabled.
  125.     */
  126.     bool    isDisabled(void) const        {return d_disabled;}
  127.  
  128.  
  129.     /*!
  130.     \brief
  131.         return whether this item will be automatically deleted when the list box it is attached to
  132.         is destroyed, or when the item is removed from the list box.
  133.  
  134.     \return
  135.         true if the item object will be deleted by the system when the list box it is attached to is
  136.         destroyed, or when the item is removed from the list.  false if client code must destroy the
  137.         item after it is removed from the list.
  138.     */
  139.     bool    isAutoDeleted(void) const    {return d_autoDelete;}
  140.  
  141.  
  142.     /*!
  143.     \brief
  144.         Get the owner window for this ListboxItem.
  145.         
  146.         The owner of a ListboxItem is typically set by the list box widgets when an item is added or inserted.
  147.  
  148.     \return
  149.         Ponter to the window that is considered the owner of this ListboxItem.
  150.     */
  151.     const Window*    getOwnerWindow(const Window* owner)        {return d_owner;}
  152.  
  153.  
  154.     /*!
  155.     \brief
  156.         Return the current colours used for selection highlighting.
  157.  
  158.     \return
  159.         ColourRect object describing the currently set colours
  160.     */
  161.     ColourRect    getSelectionColours(void) const        {return d_selectCols;}
  162.  
  163.  
  164.     /*!
  165.     \brief
  166.         Return the current selection highlighting brush.
  167.  
  168.     \return
  169.         Pointer to the Image object currently used for selection highlighting.
  170.     */
  171.     const Image*    getSelectionBrushImage(void) const        {return d_selectBrush;}
  172.  
  173.  
  174.     /*************************************************************************
  175.         Manipulators
  176.     *************************************************************************/
  177.     /*!
  178.     \brief
  179.         set the text string for this list box item.
  180.  
  181.         Note that even if the item does not render text, the text string can still be useful, since it
  182.         is used for sorting list box items.
  183.  
  184.     \param text
  185.         String object containing the text to set for the list box item.
  186.  
  187.     \return
  188.         Nothing.
  189.     */
  190.     void    setText(const String& text)        {d_itemText = text;}
  191.  
  192.     void    setTooltipText(const String& text)        {d_tooltipText = text;}
  193.  
  194.     /*!
  195.     \brief
  196.         Set the ID assigned to this list box item.
  197.  
  198.         Note that the system does not make use of this value, client code can assign any meaning it
  199.         wishes to the ID.
  200.  
  201.     \param item_id
  202.         ID code to be assigned to this list box item
  203.  
  204.     \return
  205.         Nothing.
  206.     */
  207.     void    setID(uint item_id)        {d_itemID = item_id;}
  208.  
  209.  
  210.     /*!
  211.     \brief
  212.         Set the client assigned user data attached to this lis box item.
  213.  
  214.         Note that the system does not make use of this data, client code can assign any meaning it
  215.         wishes to the attached data.
  216.  
  217.     \param item_data
  218.         Pointer to the user data to attach to this list item.
  219.  
  220.     \return
  221.         Nothing.
  222.     */
  223.     void    setUserData(void* item_data)    {d_itemData = item_data;}
  224.  
  225.  
  226.     /*!
  227.     \brief
  228.         set whether this item is selected.
  229.  
  230.     \param setting
  231.         true if the item is selected, false if the item is not selected.
  232.  
  233.     \return
  234.         Nothing.
  235.     */
  236.     void    setSelected(bool setting)        {d_selected = setting;}
  237.  
  238.  
  239.     /*!
  240.     \brief
  241.         set whether this item is disabled.
  242.  
  243.     \param setting
  244.         true if the item is disabled, false if the item is enabled.
  245.  
  246.     \return
  247.         Nothing.
  248.     */
  249.     void    setDisabled(bool setting)        {d_disabled = setting;}
  250.  
  251.     /*!
  252.     \brief
  253.         Set whether this item will be automatically deleted when the list box it is attached to
  254.         is destroyed, or when the item is removed from the list box.
  255.  
  256.     \param setting
  257.         true if the item object should be deleted by the system when the list box it is attached to is
  258.         destroyed, or when the item is removed from the list.  false if client code will destroy the
  259.         item after it is removed from the list.
  260.  
  261.     \return
  262.         Nothing.
  263.     */
  264.     void    setAutoDeleted(bool setting)        {d_autoDelete = setting;}
  265.  
  266.  
  267.     /*!
  268.     \brief
  269.         Set the owner window for this ListboxItem.  This is called by all the list box widgets when
  270.         an item is added or inserted.
  271.  
  272.     \param owner
  273.         Ponter to the window that should be considered the owner of this ListboxItem.
  274.  
  275.     \return
  276.         Nothing
  277.     */
  278.     void    setOwnerWindow(const Window* owner)        {d_owner = owner;}
  279.  
  280.  
  281.     /*!
  282.     \brief
  283.         Set the colours used for selection highlighting.
  284.  
  285.     \param cols
  286.         ColourRect object describing the colours to be used.
  287.  
  288.     \return
  289.         Nothing.
  290.     */
  291.     void    setSelectionColours(const ColourRect& cols)        {d_selectCols = cols;}
  292.  
  293.  
  294.     /*!
  295.     \brief
  296.         Set the colours used for selection highlighting.
  297.  
  298.     \param top_left_colour
  299.         Colour (as ARGB value) to be applied to the top-left corner of the selection area.
  300.  
  301.     \param top_right_colour
  302.         Colour (as ARGB value) to be applied to the top-right corner of the selection area.
  303.  
  304.     \param bottom_left_colour
  305.         Colour (as ARGB value) to be applied to the bottom-left corner of the selection area.
  306.  
  307.     \param bottom_right_colour
  308.         Colour (as ARGB value) to be applied to the bottom-right corner of the selection area.
  309.  
  310.     \return 
  311.         Nothing.
  312.     */
  313.     void    setSelectionColours(colour top_left_colour, colour top_right_colour, colour bottom_left_colour, colour bottom_right_colour);
  314.  
  315.  
  316.     /*!
  317.     \brief
  318.         Set the colours used for selection highlighting.
  319.  
  320.     \param col
  321.         colour value to be used when rendering.
  322.  
  323.     \return
  324.         Nothing.
  325.     */
  326.     void    setSelectionColours(colour col)        {setSelectionColours(col, col, col, col);}
  327.  
  328.  
  329.     /*!
  330.     \brief
  331.         Set the selection highlighting brush image.
  332.  
  333.     \param image
  334.         Pointer to the Image object to be used for selection highlighting.
  335.  
  336.     \return
  337.         Nothing.
  338.     */
  339.     void    setSelectionBrushImage(const Image* image)        {d_selectBrush = image;}
  340.  
  341.  
  342.     /*!
  343.     \brief
  344.         Set the selection highlighting brush image.
  345.  
  346.     \param imageset
  347.         Name of the imagest containing the image to be used.
  348.  
  349.     \param image
  350.         Name of the image to be used
  351.  
  352.     \return
  353.         Nothing.
  354.     */
  355.     void    setSelectionBrushImage(const String& imageset, const String& image);
  356.  
  357.  
  358.     /*************************************************************************
  359.         Abstract portion of interface
  360.     *************************************************************************/
  361.     /*!
  362.     \brief
  363.         Return the rendered pixel size of this list box item.
  364.  
  365.     \return
  366.         Size object describing the size of the list box item in pixels.
  367.     */
  368.     virtual    Size    getPixelSize(void) const    = 0;
  369.  
  370.  
  371.     /*!
  372.     \brief
  373.         Draw the list box item in its current state
  374.  
  375.     \param position
  376.         Vecor3 object describing the upper-left corner of area that should be rendered in to for the draw operation.
  377.  
  378.     \param alpha
  379.         Alpha value to be used when rendering the item (between 0.0f and 1.0f).
  380.  
  381.     \param clipper
  382.         Rect object describing the clipping rectangle for the draw operation.
  383.  
  384.     \return
  385.         Nothing.
  386.     */
  387.     virtual    void    draw(const Vector3& position, float alpha, const Rect& clipper) const    = 0;
  388.  
  389.     virtual void    draw(RenderCache& cache,const Rect& targetRect, float zBase,  float alpha, const Rect* clipper) const = 0;
  390.  
  391.     /*************************************************************************
  392.         Operators
  393.     *************************************************************************/
  394.     /*!
  395.     \brief
  396.         Less-than operator, compares item texts.
  397.     */
  398.     virtual    bool    operator<(const ListboxItem& rhs) const        {return d_itemText < rhs.getText();}
  399.  
  400.  
  401.     /*!
  402.     \brief
  403.         Greater-than operator, compares item texts.
  404.     */
  405.     virtual    bool    operator>(const ListboxItem& rhs) const        {return d_itemText > rhs.getText();}
  406.  
  407.  
  408. protected:
  409.     /*************************************************************************
  410.         Implementation methods
  411.     *************************************************************************/
  412.     /*!
  413.     \brief
  414.         Return a ColourRect object describing the colours in \a cols after having their alpha
  415.         component modulated by the value \a alpha.
  416.     */
  417.     ColourRect getModulateAlphaColourRect(const ColourRect& cols, float alpha) const;
  418.  
  419.  
  420.     /*!
  421.     \brief
  422.         Return a colour value describing the colour specified by \a col after having its alpha
  423.         component modulated by the value \a alpha.
  424.     */
  425.     colour calculateModulatedAlphaColour(colour col, float alpha) const;
  426.  
  427.  
  428.     /*************************************************************************
  429.         Implementation Data
  430.     *************************************************************************/
  431.     String    d_itemText;        //!< Text for this list box item.  If not rendered, this is still used for list sorting.
  432.     String  d_tooltipText;  //!< Text for the individual tooltip of this item
  433.     uint    d_itemID;        //!< ID code assigned by client code.  This has no meaning within the GUI system.
  434.     void*    d_itemData;        //!< Pointer to some client code data.  This has no meaning within the GUI system.
  435.     bool    d_selected;        //!< true if this item is selected.  false if the item is not selected.
  436.     bool    d_disabled;        //!< true if this item is disabled.  false if the item is not disabled.
  437.     bool    d_autoDelete;    //!< true if the system should destroy this item, false if client code will destroy the item.
  438.     const Window*    d_owner;    //!< Pointer to the window that owns this item.
  439.     ColourRect        d_selectCols;        //!< Colours used for selection highlighting.
  440.     const Image*    d_selectBrush;        //!< Image used for rendering selection.
  441. };
  442.  
  443. } // End of  CEGUI namespace section
  444.  
  445.  
  446. #endif    // end of guard _CEGUIListboxItem_h_
  447.